import java.util.ArrayList;
import java.util.List;
//二叉树
class Solution1{
    class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    //展开后的单链表应该与二叉树 先序遍历 顺序相同。
    ///114. 二叉树展开为链表
    public void flatten(TreeNode root) {
        List<TreeNode> list=new ArrayList<>();
       //前序遍历
        preorder(root,list);
        int size=list.size();
        for(int i=0;i<size-1;i++){
            TreeNode prev=list.get(i);
            TreeNode cur=list.get(i+1);
            prev.left=null;
            prev.right=cur;
        }
    }
    public void preorder(TreeNode root,List<TreeNode>list){
        if(root==null){
            return;
        }
        list.add(root);
        preorder(root.left,list);
        preorder(root.right,list);
    }
}